package sf.jooq.mapper;

import org.jooq.Select;
import sf.common.wrapper.Page;
import sf.core.DBObject;
import sf.database.dao.DBContext;
import sf.jooq.tables.JooqTable;

import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Stream;

public interface JooqMapper<T extends DBObject> {
    /**
     * @return
     */
    JooqTable<?> jooqTable();

    /**
     * @param context
     * @return
     */
    JooqTable<?> jooqTable(DBContext context);

    /**
     * @param select
     * @return
     */
    T jooqSelectOne(Select<?> select);

    /**
     * @param select
     * @param clz
     * @param <S>
     * @return
     */
    <S> S jooqSelectOne(Select<?> select, Class<S> clz);

    /**
     * @param select
     * @return
     */
    List<T> jooqSelectList(Select<?> select);

    /**
     * @param countSelect
     * @param pageSelect
     * @return
     */
    Page<T> jooqSelectPage(Select<?> countSelect, Select<?> pageSelect);

    /**
     * @param ormIt
     * @param select
     */
    void jooqSelectIterator(Consumer<Iterable<T>> ormIt, Select<?> select);

    /**
     * @param ormStream
     * @param select
     */
    void jooqSelectStream(Consumer<Stream<T>> ormStream, Select<?> select);
}
